package com.xinbochuang.machine.admin.controller.macroom;


import cn.hutool.json.JSONUtil;
import com.xinbochuang.machine.admin.domain.macRoom.MacShow;
import com.xinbochuang.machine.admin.domain.macRoom.json.*;
import com.xinbochuang.machine.admin.service.macRoom.IMacShowService;
import com.xinbochuang.machine.common.controller.BaseController;
import com.xinbochuang.machine.framework.web.domain.AjaxResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 黄晓鹏
 * @date 2020-11-20
 */
@RestController
@RequestMapping("/mac-show")
public class MacShowController extends BaseController {

    @Resource
    private IMacShowService macShowService;

    /**
     * 根据机房id查询所有节点
     */
    @PreAuthorize("@ss.hasPermi('system:macroom:show')")
    @GetMapping(value = "/{macId}")
    public AjaxResult info(@PathVariable String macId) {
        List<MacShow> points = macShowService.getNodes(macId);
        List<Node> nodes = new ArrayList<>();
        for (MacShow point : points) {
            Node node = JSONUtil.toBean(point.getNode(), Node.class);
            node.setId(point.getId());
            node.setUNum(point.getUNum());
            node.setCabinetId(point.getCabinetId());
            // 使用机柜图片
//            node.setType("cabinet");
//            node.setWidth(40);
//            node.setHeight(80);
//            node.setSize(new double[]{40, 80});
//            LabelCfg labelCfg = new LabelCfg();
//            labelCfg.setPosition("top");
//            labelCfg.setOffset(8);
//            LabelStyle labelStyle = new LabelStyle();
//            labelStyle.setFontSize(16);
//            labelStyle.setLineWidth(2);
//            labelStyle.setFill("#FFFFFFFF");
//            labelStyle.setStroke("#000000FF");
//            labelStyle.setShadowColor("#000000FF");
//            labelCfg.setStyle(labelStyle);
//            node.setLabelCfg(labelCfg);
            // 旋转角度
//            node.setRadian("0.16249224775247018");
            nodes.add(node);
        }
        DataJson json = new DataJson();
        json.setNodes(nodes);
        return AjaxResult.data(json);
    }

    /**
     * 保存节点数据
     */
    @PreAuthorize("@ss.hasPermi('system:macroom:save')")
    @PostMapping("/save")
    public AjaxResult save(@RequestBody DataNode dataNode) {
        return toAjax(macShowService.saveNodes(dataNode));
    }

}

